import axios from 'axios';

const API_URL = 'http://172.16.103.206:8081/api';

export interface QuestionBank {
    id: string;
    name: string;
    questionCount: number;
    createdAt: string;
}

export interface QuestionBankResponse {
    data: QuestionBank[];
    total: number;
}

export interface CreateQuestionBankData {
    name: string;
}

export interface UpdateQuestionBankData extends Partial<CreateQuestionBankData> {}

// 创建题库
export const createQuestionBank = async (data: CreateQuestionBankData): Promise<QuestionBank> => {
    const response = await axios.post(`${API_URL}/question-banks`, data, {
        headers: {
            Authorization: `Bearer ${localStorage.getItem('token')}`
        }
    });
    return response.data;
};

// 获取题库列表
export const getQuestionBanks = async (params?: { id?: string; page?: number; pageSize?: number }): Promise<QuestionBankResponse> => {
    const response = await axios.get(`${API_URL}/question-banks`, {
        params,
        headers: {
            Authorization: `Bearer ${localStorage.getItem('token')}`
        }
    });
    return response.data;
};

// 更新题库
export const updateQuestionBank = async (id: string, data: UpdateQuestionBankData): Promise<QuestionBank> => {
    const response = await axios.put(`${API_URL}/question-banks/${id}`, data, {
        headers: {
            Authorization: `Bearer ${localStorage.getItem('token')}`
        }
    });
    return response.data;
};

// 删除题库
export const deleteQuestionBank = async (id: string): Promise<void> => {
    await axios.delete(`${API_URL}/question-banks/${id}`, {
        headers: {
            Authorization: `Bearer ${localStorage.getItem('token')}`
        }
    });
}; 